package org.traffometer.packet.location;

import junit.framework.TestCase;

/**
 * Tests the functionality of the Longitude class. 
 *
 * @author Aaron A. Kagawa
 * @version $Id$
 */
public class TestLongitude extends TestCase {

  /** Tests the decimal constructor of the Longitude class. */
  public void testLongitudeDecimalConstructor() {
    Longitude longitude = new Longitude(46.17444);
    assertEquals("checking the longitude value in sexagesimal", 
        46.17444, longitude.toSexagesimal(), 0.0000);
    assertEquals("checking the longitude toString", "46 10'27.98399999998935'' E",
        longitude.toString());
  }
  
  /** Tests the degrees, minutes, seconds, hemisphere constructor of the Longitude class. */
  public void testLongitudeDegreeMinuteSecondHemisphereConstructor() {
    try {
      Longitude longitude = new Longitude(46, 10, 28.0, Hemisphere.East);
      assertEquals("checking the longitude value in sexagesimal", 
          46.17444, longitude.toSexagesimal(), 0.0001);
      assertEquals("checking the degree value of the longitude", 46, longitude.getDegrees());
      assertEquals("checking the minute value of the longitude", 10, longitude.getMinutes());
      assertEquals("checking the seconds value of the longitude", 28.0, 
          longitude.getSeconds(), 0.1);
    }
    catch (LocationException e) {
      fail("should not throw an exception: " + e.getMessage());
    }
    try {
      new Longitude(0, 0, 0, Hemisphere.North);
      fail("should not reach here. an exception should be thrown in constructor");
    }
    catch (LocationException e) {
      assertNotNull("exception object should not be null", e);
    }
    try {
      new Longitude(0, 0, 0, Hemisphere.South);
      fail("should not reach here. an exception should be thrown in constructor");
    }
    catch (LocationException e) {
      assertNotNull("exception object should not be null", e);
    }
    try {
      new Longitude(-1, 0, 0, Hemisphere.West);
      fail("should not reach here. an exception should be thrown in constructor");
    }
    catch (LocationException e) {
      assertNotNull("exception object should not be null", e);
    }
    try {
      new Longitude(0, -1, 0, Hemisphere.West);
      fail("should not reach here. an exception should be thrown in constructor");
    }
    catch (LocationException e) {
      assertNotNull("exception object should not be null", e);
    }
    try {
      new Longitude(0, 0, -1, Hemisphere.West);
      fail("should not reach here. an exception should be thrown in constructor");
    }
    catch (LocationException e) {
      assertNotNull("exception object should not be null", e);
    }
  }
}